#include "OpenCLKernel.h"
#include <stdio.h>


int main()
{
	char deviceName[1024];                          //this string will hold the devices name
	char vendor[1024];                              //this strirng will hold a platforms vendor
	cl_bool available;								//this variable holds if the device is available
	cl_uint numberOfCores;                          //this variable holds the number of cores of on a device
	cl_uint clockFreq;                              //this variable holds the clock frequency of a device
	cl_long amountOfMemory;                         //this variable holds the amount of memory on a device
	cl_ulong maxAlocatableMem;                      //this variable holds the maximum allocatable memory
	cl_ulong localMem;                              //this variable holds local memory for a device
	cl_uint charWidth;								//this variable holds the preferred vector width of char
	cl_uint floatWidth;								//this variable holds the preferred vector width of float

	cl_int err;

	OpenCLKernel * m_pOCL = new OpenCLKernel;
	if (0 != m_pOCL->OpenCLInitialize())
	{
		delete m_pOCL;
		m_pOCL = nullptr;
	}

	int devs = (unsigned int)m_pOCL->GetDeviceCount();
	printf("Devices count is :%d;\n", devs);

	for (int i = 0; i < devs; i++)
	{
		err = clGetDeviceInfo(m_pOCL->GetDevices()[i], CL_DEVICE_NAME, sizeof(deviceName), deviceName, NULL);
		GET_CL_ERROR(err, m_pOCL);
		
		err = clGetDeviceInfo(m_pOCL->GetDevices()[i], CL_DEVICE_VENDOR, sizeof(vendor), vendor, NULL);
		GET_CL_ERROR(err, m_pOCL);

		err = clGetDeviceInfo(m_pOCL->GetDevices()[i], CL_DEVICE_AVAILABLE, sizeof(available), &available, NULL);
		GET_CL_ERROR(err, m_pOCL);
		
		err = clGetDeviceInfo(m_pOCL->GetDevices()[i], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(numberOfCores), &numberOfCores, NULL);
		GET_CL_ERROR(err, m_pOCL);

		err = clGetDeviceInfo(m_pOCL->GetDevices()[i], CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof(clockFreq), &clockFreq, NULL);
		GET_CL_ERROR(err, m_pOCL);

		err = clGetDeviceInfo(m_pOCL->GetDevices()[i], CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(amountOfMemory), &amountOfMemory, NULL);
		GET_CL_ERROR(err, m_pOCL);

		err = clGetDeviceInfo(m_pOCL->GetDevices()[i], CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(maxAlocatableMem), &maxAlocatableMem, NULL);
		GET_CL_ERROR(err, m_pOCL);

		err = clGetDeviceInfo(m_pOCL->GetDevices()[i], CL_DEVICE_LOCAL_MEM_SIZE, sizeof(localMem), &localMem, NULL);
		GET_CL_ERROR(err, m_pOCL);

		err = clGetDeviceInfo(m_pOCL->GetDevices()[i], CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, sizeof(charWidth), &charWidth, NULL);
		GET_CL_ERROR(err, m_pOCL);

		err = clGetDeviceInfo(m_pOCL->GetDevices()[i], CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, sizeof(floatWidth), &floatWidth, NULL);
		GET_CL_ERROR(err, m_pOCL);

		printf("\tDevice: %u\n", i);
		printf("\t\tName:\t\t\t\t%s\n", deviceName);
		printf("\t\tVendor:\t\t\t\t%s\n", vendor);
		printf("\t\tAvailable:\t\t\t%s\n", available ? "Yes" : "No");
		printf("\t\tCompute Units:\t\t\t%u\n", numberOfCores);
		printf("\t\tClock Frequency:\t\t%u mHz\n", clockFreq);
		printf("\t\tGlobal Memory:\t\t\t%0.00f mb\n", (double)amountOfMemory / 1048576);
		printf("\t\tMax Allocateable Memory:\t%0.00f mb\n", (double)maxAlocatableMem / 1048576);
		printf("\t\tLocal Memory:\t\t\t%u kb\n", (unsigned int)localMem);
		printf("\t\tVector Width of char:\t\t%u\n", charWidth);
		printf("\t\tVector Width of float:\t\t%u\n", floatWidth);
		printf("\n");
	}

	delete m_pOCL;
	return 0;
}
